package com;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBC_02_Batch_PreparedStatement {

	public static void main(String[] args) {
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		try {
			connection = DBUtil.getConnection();
			String sql = "insert into test (name,age) values (?,?)";
			long startTime = System.currentTimeMillis();
			preparedStatement = connection.prepareStatement(sql);
			for (int i = 0; i < 100; i++) {
				preparedStatement.setString(1, "张三_" + i);
				preparedStatement.setInt(2, 18);
				preparedStatement.addBatch();
			}
			preparedStatement.executeBatch();
			long endTime = System.currentTimeMillis();
			System.out.println("执行成功 : " + (endTime - startTime));
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				DBUtil.close(preparedStatement);
				DBUtil.close(connection);
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}

}
